﻿using System;

namespace Poly2Tri
{
	// Token: 0x020003ED RID: 1005
	public class DTSweepContext : TriangulationContext
	{
		// Token: 0x06001B77 RID: 7031 RVA: 0x000AE7C0 File Offset: 0x000AC9C0
		public DTSweepContext()
		{
			this.Clear();
		}

		// Token: 0x170003C4 RID: 964
		// (get) Token: 0x06001B78 RID: 7032 RVA: 0x000AE7FA File Offset: 0x000AC9FA
		// (set) Token: 0x06001B79 RID: 7033 RVA: 0x000AE802 File Offset: 0x000ACA02
		public TriangulationPoint Head { get; set; }

		// Token: 0x170003C5 RID: 965
		// (get) Token: 0x06001B7A RID: 7034 RVA: 0x000AE80B File Offset: 0x000ACA0B
		// (set) Token: 0x06001B7B RID: 7035 RVA: 0x000AE813 File Offset: 0x000ACA13
		public TriangulationPoint Tail { get; set; }

		// Token: 0x170003C6 RID: 966
		// (get) Token: 0x06001B7C RID: 7036 RVA: 0x0001D4CA File Offset: 0x0001B6CA
		public override TriangulationAlgorithm Algorithm
		{
			get
			{
				return TriangulationAlgorithm.DTSweep;
			}
		}

		// Token: 0x170003C7 RID: 967
		// (get) Token: 0x06001B7D RID: 7037 RVA: 0x000AE81C File Offset: 0x000ACA1C
		// (set) Token: 0x06001B7E RID: 7038 RVA: 0x000AE824 File Offset: 0x000ACA24
		public override bool IsDebugEnabled
		{
			get
			{
				return base.IsDebugEnabled;
			}
			protected set
			{
				if (value && base.DebugContext == null)
				{
					base.DebugContext = new DTSweepDebugContext(this);
				}
				base.IsDebugEnabled = value;
			}
		}

		// Token: 0x06001B7F RID: 7039 RVA: 0x000AE84A File Offset: 0x000ACA4A
		public void RemoveFromList(DelaunayTriangle triangle)
		{
			this.Triangles.Remove(triangle);
		}

		// Token: 0x06001B80 RID: 7040 RVA: 0x000AE859 File Offset: 0x000ACA59
		public void MeshClean(DelaunayTriangle triangle)
		{
			this.MeshCleanReq(triangle);
		}

		// Token: 0x06001B81 RID: 7041 RVA: 0x000AE864 File Offset: 0x000ACA64
		private void MeshCleanReq(DelaunayTriangle triangle)
		{
			if (triangle != null && !triangle.IsInterior)
			{
				triangle.IsInterior = true;
				base.Triangulatable.AddTriangle(triangle);
				for (int i = 0; i < 3; i++)
				{
					if (!triangle.EdgeIsConstrained[i])
					{
						this.MeshCleanReq(triangle.Neighbors[i]);
					}
				}
			}
		}

		// Token: 0x06001B82 RID: 7042 RVA: 0x000AE8CD File Offset: 0x000ACACD
		public override void Clear()
		{
			base.Clear();
			this.Triangles.Clear();
		}

		// Token: 0x06001B83 RID: 7043 RVA: 0x000AE8E0 File Offset: 0x000ACAE0
		public void AddNode(AdvancingFrontNode node)
		{
			this.Front.AddNode(node);
		}

		// Token: 0x06001B84 RID: 7044 RVA: 0x000AE8EE File Offset: 0x000ACAEE
		public void RemoveNode(AdvancingFrontNode node)
		{
			this.Front.RemoveNode(node);
		}

		// Token: 0x06001B85 RID: 7045 RVA: 0x000AE8FC File Offset: 0x000ACAFC
		public AdvancingFrontNode LocateNode(TriangulationPoint point)
		{
			return this.Front.LocateNode(point);
		}

		// Token: 0x06001B86 RID: 7046 RVA: 0x000AE90C File Offset: 0x000ACB0C
		public void CreateAdvancingFront()
		{
			DelaunayTriangle delaunayTriangle = new DelaunayTriangle(this.Points[0], this.Tail, this.Head);
			this.Triangles.Add(delaunayTriangle);
			AdvancingFrontNode advancingFrontNode = new AdvancingFrontNode(delaunayTriangle.Points[1]);
			advancingFrontNode.Triangle = delaunayTriangle;
			AdvancingFrontNode advancingFrontNode2 = new AdvancingFrontNode(delaunayTriangle.Points[0]);
			advancingFrontNode2.Triangle = delaunayTriangle;
			AdvancingFrontNode tail = new AdvancingFrontNode(delaunayTriangle.Points[2]);
			this.Front = new AdvancingFront(advancingFrontNode, tail);
			this.Front.AddNode(advancingFrontNode2);
			this.Front.Head.Next = advancingFrontNode2;
			advancingFrontNode2.Next = this.Front.Tail;
			advancingFrontNode2.Prev = this.Front.Head;
			this.Front.Tail.Prev = advancingFrontNode2;
		}

		// Token: 0x06001B87 RID: 7047 RVA: 0x000AE9E4 File Offset: 0x000ACBE4
		public void MapTriangleToNodes(DelaunayTriangle t)
		{
			for (int i = 0; i < 3; i++)
			{
				if (t.Neighbors[i] == null)
				{
					AdvancingFrontNode advancingFrontNode = this.Front.LocatePoint(t.PointCWFrom(t.Points[i]));
					if (advancingFrontNode != null)
					{
						advancingFrontNode.Triangle = t;
					}
				}
			}
		}

		// Token: 0x06001B88 RID: 7048 RVA: 0x000AEA40 File Offset: 0x000ACC40
		public override void PrepareTriangulation(ITriangulatable t)
		{
			base.PrepareTriangulation(t);
			double x;
			double num = x = this.Points[0].X;
			double y;
			double num2 = y = this.Points[0].Y;
			foreach (TriangulationPoint triangulationPoint in this.Points)
			{
				if (triangulationPoint.X > x)
				{
					x = triangulationPoint.X;
				}
				if (triangulationPoint.X < num)
				{
					num = triangulationPoint.X;
				}
				if (triangulationPoint.Y > y)
				{
					y = triangulationPoint.Y;
				}
				if (triangulationPoint.Y < num2)
				{
					num2 = triangulationPoint.Y;
				}
			}
			double num3 = (double)this.ALPHA * (x - num);
			double num4 = (double)this.ALPHA * (y - num2);
			TriangulationPoint head = new TriangulationPoint(x + num3, num2 - num4);
			TriangulationPoint tail = new TriangulationPoint(num - num3, num2 - num4);
			this.Head = head;
			this.Tail = tail;
			this.Points.Sort(this._comparator);
		}

		// Token: 0x06001B89 RID: 7049 RVA: 0x000AEB74 File Offset: 0x000ACD74
		public void FinalizeTriangulation()
		{
			base.Triangulatable.AddTriangles(this.Triangles);
			this.Triangles.Clear();
		}

		// Token: 0x06001B8A RID: 7050 RVA: 0x000AEB92 File Offset: 0x000ACD92
		public override TriangulationConstraint NewConstraint(TriangulationPoint a, TriangulationPoint b)
		{
			return new DTSweepConstraint(a, b);
		}

		// Token: 0x04001D4F RID: 7503
		private readonly float ALPHA = 0.3f;

		// Token: 0x04001D50 RID: 7504
		public AdvancingFront Front;

		// Token: 0x04001D53 RID: 7507
		public DTSweepBasin Basin = new DTSweepBasin();

		// Token: 0x04001D54 RID: 7508
		public DTSweepEdgeEvent EdgeEvent = new DTSweepEdgeEvent();

		// Token: 0x04001D55 RID: 7509
		private DTSweepPointComparator _comparator = new DTSweepPointComparator();
	}
}
